package com.example.filter;

import org.apache.dubbo.common.constants.CommonConstants;
import org.apache.dubbo.common.extension.Activate;
import org.apache.dubbo.rpc.*;

import static com.example.common.DubboPracticeConstants.TRANSPORT_IP_KEY;

/**
 * @author zhouyp
 * @program dubbo-practice
 * @description
 * @create 2020-07-08
 */
@Activate(group = CommonConstants.CONSUMER)
public class TransportIPFilter implements Filter {

	@Override
	public Result invoke(Invoker<?> invoker, Invocation invocation)
			throws RpcException {
		String attachment = RpcContext.getContext()
				.getAttachment(TRANSPORT_IP_KEY);
		System.out.println("rpc传输的ip为： " + attachment);
		return invoker.invoke(invocation);
	}

}
